import time

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from common.Utils import ForumDriver

class ForumPub:
    driver = ""
    def __init__(self):
        self.driver = ForumDriver.driver

    def ForumPubPageelements(self):
        #在论坛首页点击，发布贴子按钮
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #先检查一下页面元素
        #板块
        text = self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad").text
        print("板块："+text)
        #标题
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title")
        #内容输入框
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")
        #发布按钮
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")

    def FPfunPageFunctions(self):
        #测试内容为空
        # self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("第一篇贴子")
        # input_element = self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")
        # action = ActionChains(self.driver)
        # action.click(input_element).send_keys(Keys.RETURN).perform()
        # open = self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit")
        # action.move_to_element(open).click().perform()
        # time.sleep(1)
        # ForumDriver.GetScreeShot()

        # 标题为空
        input_element = self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")
        action = ActionChains(self.driver)
        action.click(input_element).send_keys("第一次测试").send_keys(Keys.RETURN).perform()
        open = self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit")
        action.move_to_element(open).click().perform()
        time.sleep(1)
        ForumDriver.GetScreeShot()

        # 标题为空，内容为空
        input_element = self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")
        action = ActionChains(self.driver)
        action.click(input_element).send_keys(Keys.RETURN).perform()
        open = self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit")
        action.move_to_element(open).click().perform()
        time.sleep(1)
        ForumDriver.GetScreeShot()








